package com.bjsxt.base.sync_shuoGG;

import java.text.SimpleDateFormat;
import java.util.Date;

public class StaticUtil {

    private StaticUtil() {
    }

    public static void test1() {
        synchronized (StaticUtil.class) {
            System.out.println(Thread.currentThread().getName() + " UseLock StaticUtil.test1 " + new SimpleDateFormat("HH:mm:ss").format(new Date()));
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + " ReleaseLock StaticUtil.test1 " + new SimpleDateFormat("HH:mm:ss").format(new Date()));
        }
    }

    public static void test2() {
        synchronized (StaticUtil.class) {
            System.out.println(Thread.currentThread().getName() + " UseLock StaticUtil.test2 " + new SimpleDateFormat("HH:mm:ss").format(new Date()));
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + " ReleaseLock StaticUtil.test2 " + new SimpleDateFormat("HH:mm:ss").format(new Date()));
        }
    }

}
